Added 'logs' option to text/html/palmdoc
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 8 Jun 2004 17:42:12 +0000 (17:42 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 8 Jun 2004 17:42:12 +0000 (17:42 +0000)
gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/html.c
gpsbabel/palmdoc.c
gpsbabel/text.c
gpsbabel/util.c

index 3fbe48bb367ee8cc6133e23447fdbbc6d802dafa..85b275c10dea7dad4c67cea837d49413077048c6 100644 (file)
@@ -435,6 +435,13 @@ char * strip_nastyhtml(const char * in);
 char * str_utf8_to_cp1252( const char * str );
 char * str_utf8_to_ascii( const char * str );
 
+/* this lives in gpx.c */
+time_t xml_parse_time( char *cdatastr );
+       
+xml_tag *xml_findfirst( xml_tag *root, char *tagname );
+xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname );
+char *xml_attribute( xml_tag *tag, char *attrname );
+
 char * rot13( const char *str );
 
 /*
index 871aa8fc5ce7ee00cf2e4b78e44d0c26c59c694d..ba12e4b14d96807df916a672bf1cd1dbf6bc701e 100644 (file)
@@ -542,7 +542,6 @@ gs_get_container(geocache_container t)
        return "Unknown";
 }
 
-static
 time_t 
 xml_parse_time( char *cdatastr ) 
 {
index 41a71d886ae3fcc3d16d5bf5f46fdcde06aad29b..4a55924e3e0deded1bbcd49c3ff09aab7b7b490a 100644 (file)
@@ -29,6 +29,7 @@ static void *mkshort_handle;
 
 static char *stylesheet = NULL;
 static char *encrypt = NULL;
+static char *includelogs = NULL;
 
 #define MYNAME "HTML"
 
@@ -38,6 +39,8 @@ arglist_t html_args[] = {
                "Path to HTML style sheet", ARGTYPE_STRING },
        { "encrypt", &encrypt,
                "Encrypt hints using ROT13", ARGTYPE_BOOL },
+       { "logs", &includelogs, 
+               "Include groundspeak logs if present", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
 
@@ -81,8 +84,8 @@ html_disp(const waypoint *wpt)
        fprintf(file_out, "<a name=\"%s\"></a><table width=\"100%%\"><tr><td>\n", wpt->shortname);
        fprintf(file_out, "<h3 class=\"waypoint\">%s - %c%d&deg;%06.3f %c%d&deg;%06.3f (%ld%c %6.0f %7.0f)",
                (global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname,
-               wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), 
-               wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint),
+               wpt->latitude < 0 ? 'S' : 'N',  latint, 60.0 * (fabs(wpt->latitude) - latint), 
+               wpt->longitude < 0 ? 'W' : 'E', lonint, 60.0 * (fabs(wpt->longitude) - lonint),
                utmz, utmzc, utme, utmn);
        if (wpt->altitude != unknown_alt) 
                fprintf (file_out, " alt: %1.1f", wpt->altitude);
@@ -119,6 +122,94 @@ html_disp(const waypoint *wpt)
        else if (!wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
                fprintf (file_out, "<p class=\"notes\">%s</p>\n", wpt->notes);
        }
+       if ( includelogs && wpt->gpx_extras ) {
+               xml_tag *root = wpt->gpx_extras;
+               xml_tag *curlog = NULL;
+               xml_tag *logpart = NULL;
+               curlog = xml_findfirst( root, "groundspeak:log" );
+               while ( curlog ) {
+                       fprintf( file_out, "<p class=\"log\">\n" );
+                       time_t logtime = 0;
+                       struct tm *logtm = NULL;
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:type" );
+                       if ( logpart ) {
+                               fprintf( file_out, "<span class=\"logtype\">%s</span> by ", logpart->cdata );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:finder" );
+                       if ( logpart ) {
+                               char *f = html_entitize( logpart->cdata );
+                               fprintf( file_out, "<span class=\"logfinder\">%s</span> on ", f );
+                               xfree( f );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:date" );
+                       if ( logpart ) {
+                               logtime = xml_parse_time( logpart->cdata );
+                               logtm = localtime( &logtime );
+                               if ( logtm ) {
+                                       fprintf( file_out, 
+                                               "<span class=\"logdate\">%2.2d/%2.2d/%4.4d</span><br>\n",
+                                               logtm->tm_mon+1,
+                                               logtm->tm_mday,
+                                               logtm->tm_year+1900
+                                               );
+                               }
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+                       if ( logpart ) {
+                               char *coordstr = NULL;
+                               float lat = 0;
+                               int latdeg = 0;
+                               float lon = 0;
+                               int londeg = 0;
+                               coordstr = xml_attribute( logpart, "lat" );
+                               if ( coordstr ) {
+                                       lat = atof( coordstr );
+                               }
+                               coordstr = xml_attribute( logpart, "lon" );
+                               if ( coordstr ) {
+                                       lon = atof( coordstr );
+                               }
+                               latdeg = abs(lat);
+                               londeg = abs(lon);
+                               
+                               fprintf( file_out,
+                                       "<span class=\"logcoords\">%c %d&deg; %.3f' %c %d&deg; %.3f'</span><br>\n",
+                               
+                                       lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), 
+                                       lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+                               );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:text" );
+                       if ( logpart ) {
+                               char *encstr = NULL;
+                               char *s = NULL;
+                               char *t = NULL;
+                               int encoded = 0;
+                               encstr = xml_attribute( logpart, "encoded" );
+                               encoded = (encstr[0] != 'F');
+                               
+                               if ( encrypt && encoded ) {
+                                       s = rot13( logpart->cdata );
+                               }
+                               else {
+                                       s = xstrdup( logpart->cdata );
+                               }
+                                       
+                               t = html_entitize( s );
+                               fprintf( file_out, "%s", t ); 
+                               xfree( t );
+                               xfree( s );
+                       }
+
+                       fprintf( file_out, "</p>\n" );
+                       curlog = xml_findnext( root, curlog, "groundspeak:log" );
+               }
+       }
        fprintf(file_out, "</td></tr></table>\n");
 }
 
index da0416c113cbc121cfff894f7bed078fec76796f..802a0f255cef6c9e549e68089112ce20a6e3bf64 100644 (file)
@@ -37,6 +37,7 @@ static struct pdb_record *opdb_rec;
 
 static char *suppresssep = NULL;
 static char *dbname = NULL;
+static char *includelogs = NULL;
 
 static int ct = 1;
 static int offset = 0;
@@ -68,6 +69,8 @@ arglist_t palmdoc_args[] = {
                "Suppress separator lines between waypoints", ARGTYPE_BOOL },
        {"dbname", &dbname, "Database name", ARGTYPE_STRING },
        {"encrypt", &encrypt, "Encrypt hints with ROT13", ARGTYPE_BOOL },
+       { "logs", &includelogs,
+               "Include groundspeak logs if present", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
 
@@ -457,6 +460,90 @@ palmdoc_disp(const waypoint *wpt)
        else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
                docprintf (10+strlen(wpt->notes), "%s\n", wpt->notes);
        }
+
+       if ( includelogs && wpt->gpx_extras ) {
+               xml_tag *root = wpt->gpx_extras;
+               xml_tag *curlog = NULL;
+               xml_tag *logpart = NULL;
+               curlog = xml_findfirst( root, "groundspeak:log" );
+               while ( curlog ) {
+                       docprintf( 10, "\n" );
+                       time_t logtime = 0;
+                       struct tm *logtm = NULL;
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:type" );
+                       if ( logpart ) {
+                               docprintf( 10+strlen(logpart->cdata), "%s by ", logpart->cdata );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:finder" );
+                       if ( logpart ) {
+                               docprintf( 10+strlen(logpart->cdata), "%s on ", logpart->cdata );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:date" );
+                       if ( logpart ) {
+                               logtime = xml_parse_time( logpart->cdata );
+                               logtm = localtime( &logtime );
+                               if ( logtm ) {
+                                       docprintf( 15, 
+                                               "%2.2d/%2.2d/%4.4d\n",
+                                               logtm->tm_mon+1,
+                                               logtm->tm_mday,
+                                               logtm->tm_year+1900
+                                               );
+                               }
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+                       if ( logpart ) {
+                               char *coordstr = NULL;
+                               float lat = 0;
+                               int latdeg = 0;
+                               float lon = 0;
+                               int londeg = 0;
+                               coordstr = xml_attribute( logpart, "lat" );
+                               if ( coordstr ) {
+                                       lat = atof( coordstr );
+                               }
+                               coordstr = xml_attribute( logpart, "lon" );
+                               if ( coordstr ) {
+                                       lon = atof( coordstr );
+                               }
+                               latdeg = abs(lat);
+                               londeg = abs(lon);
+                               
+                               docprintf( 30,
+                                       "%c %d\xb0 %.3f' %c %d\xb0 %.3f'\n",
+                               
+                                       lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), 
+                                       lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+                               );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:text" );
+                       if ( logpart ) {
+                               char *encstr = NULL;
+                               char *s = NULL;
+                               int encoded = 0;
+                               encstr = xml_attribute( logpart, "encoded" );
+                               encoded = (encstr[0] != 'F');
+                               
+                               if ( encrypt && encoded ) {
+                                       s = rot13( logpart->cdata );
+                               }
+                               else {
+                                       s = xstrdup( logpart->cdata );
+                               }
+                                       
+                               docprintf( 5+strlen(s), "%s", s ); 
+                               xfree( s );
+                       }
+
+                       docprintf( 10, "\n" );
+                       curlog = xml_findnext( root, curlog, "groundspeak:log" );
+               }
+       }
        if (! suppresssep) 
                docprintf(50, "---------------------------\n");
        else
index 6c17eb902457c26f544bf46138ee7de8e037c502..f133da47c26e0b5e1a718f246dc767f37ed0b58a 100644 (file)
@@ -29,6 +29,7 @@ static void *mkshort_handle;
 
 static char *suppresssep = NULL;
 static char *encrypt = NULL;
+static char *includelogs = NULL;
 
 #define MYNAME "TEXT"
 
@@ -38,6 +39,8 @@ arglist_t text_args[] = {
                "Suppress separator lines between waypoints", ARGTYPE_BOOL },
        { "encrypt", &encrypt,
                "Encrypt hints using ROT13", ARGTYPE_BOOL },
+       { "logs", &includelogs,
+                "Include groundspeak logs if present", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
 
@@ -112,6 +115,90 @@ text_disp(const waypoint *wpt)
        else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
                fprintf (file_out, "%s\n", wpt->notes);
        }
+
+       if ( includelogs && wpt->gpx_extras ) {
+               xml_tag *root = wpt->gpx_extras;
+               xml_tag *curlog = NULL;
+               xml_tag *logpart = NULL;
+               curlog = xml_findfirst( root, "groundspeak:log" );
+               while ( curlog ) {
+                       fprintf( file_out, "\n" );
+                       time_t logtime = 0;
+                       struct tm *logtm = NULL;
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:type" );
+                       if ( logpart ) {
+                               fprintf( file_out, "%s by ", logpart->cdata );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:finder" );
+                       if ( logpart ) {
+                               fprintf( file_out, "%s on ", logpart->cdata );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:date" );
+                       if ( logpart ) {
+                               logtime = xml_parse_time( logpart->cdata );
+                               logtm = localtime( &logtime );
+                               if ( logtm ) {
+                                       fprintf( file_out, 
+                                               "%2.2d/%2.2d/%4.4d\n",
+                                               logtm->tm_mon+1,
+                                               logtm->tm_mday,
+                                               logtm->tm_year+1900
+                                               );
+                               }
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
+                       if ( logpart ) {
+                               char *coordstr = NULL;
+                               float lat = 0;
+                               int latdeg = 0;
+                               float lon = 0;
+                               int londeg = 0;
+                               coordstr = xml_attribute( logpart, "lat" );
+                               if ( coordstr ) {
+                                       lat = atof( coordstr );
+                               }
+                               coordstr = xml_attribute( logpart, "lon" );
+                               if ( coordstr ) {
+                                       lon = atof( coordstr );
+                               }
+                               latdeg = abs(lat);
+                               londeg = abs(lon);
+                               
+                               fprintf( file_out,
+                                       "%c %d %.3f' %c %d %.3f'\n",
+                               
+                                       lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), 
+                                       lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg)
+                               );
+                       }
+                       
+                       logpart = xml_findfirst( curlog, "groundspeak:text" );
+                       if ( logpart ) {
+                               char *encstr = NULL;
+                               char *s = NULL;
+                               int encoded = 0;
+                               encstr = xml_attribute( logpart, "encoded" );
+                               encoded = (encstr[0] != 'F');
+                               
+                               if ( encrypt && encoded ) {
+                                       s = rot13( logpart->cdata );
+                               }
+                               else {
+                                       s = xstrdup( logpart->cdata );
+                               }
+                                       
+                               fprintf( file_out, "%s", s ); 
+                               xfree( s );
+                       }
+
+                       fprintf( file_out, "\n" );
+                       curlog = xml_findnext( root, curlog, "groundspeak:log" );
+               }
+       }
        if (! suppresssep) 
                fprintf(file_out, "-----------------------------------------------------------------------------\n");
        else
index 25ffad8cac923f366099e59f2e879aa88430de89..3804a908fa8b9ecb15b550c2a4e0bd8fb00bfc93 100644 (file)
@@ -1075,3 +1075,57 @@ char * html_entitize(const char * str)
 {
        return entitize(str, 1);
 }
+
+/*
+ * xml_tag utilities
+ */
+
+xml_tag *xml_next( xml_tag *root, xml_tag *cur )
+{
+       if ( cur->child ) {
+               cur = cur->child;
+       }
+       else if ( cur->sibling ) {
+               cur = cur->sibling;
+       }
+       else {
+               cur = cur->parent;
+               if ( cur == root ) {
+                       cur = NULL;
+               }
+               if ( cur ) {
+                       cur = cur->sibling;
+               }
+       }
+       return cur;
+}
+
+xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname ) 
+{
+       xml_tag *result = cur;
+       do {
+               result = xml_next( root, result );
+       } while ( result && case_ignore_strcmp( result->tagname, tagname ));
+       return result;
+}
+
+xml_tag *xml_findfirst( xml_tag *root, char *tagname )
+{
+       return xml_findnext( root, root, tagname );
+}
+
+char *xml_attribute( xml_tag *tag, char *attrname ) 
+{
+       char *result = NULL;
+       if ( tag->attributes ) {
+               char **attr = tag->attributes;
+               while ( attr && *attr ) {
+                       if ( 0 == case_ignore_strcmp( *attr, attrname )) {
+                               result = attr[1];
+                               break;
+                       }
+                       attr+=2;
+               }
+       }
+       return result;
+}